import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { ArticleVO } from '@/types'
import { articleApi } from '@/api/article'

export const useArticleStore = defineStore('article', () => {
  const articles = ref<ArticleVO[]>([])
  const currentArticle = ref<ArticleVO | null>(null)

  const fetchArticles = async (params: any) => {
    const response = await articleApi.getArticles(params)
    articles.value = response.data.data
  }

  const fetchArticle = async (id: number) => {
    const response = await articleApi.getArticleById(id)
    currentArticle.value = response.data
  }

  return {
    articles,
    currentArticle,
    fetchArticles,
    fetchArticle,
  }
})
